﻿using System;

namespace Core
{
    public static class DateTimeHelper
    {
        /// <summary>
        /// 时间转换为事件戳
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static uint GetTimeStamp(DateTime dateTime)
        {
            DateTime DateStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            return Convert.ToUInt32((dateTime - DateStart).TotalSeconds);
        }
        /// 时间戳转为C#格式时间  
        /// </summary>  
        /// <param name=”timeStamp”></param>  
        /// <returns></returns>  
        public static DateTime GetTimeFromUint(string timeStamp)
        {
            long timestamp = long.Parse(timeStamp);
            DateTime baseTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            DateTime date = baseTime.AddSeconds(timestamp).ToLocalTime();
            return date;
        }
    }
}
